package com.knight.concurrent.chapter9;

/**
 * @Description:线程异常处理
 * @author: knight
 * @Date: 2019-03-09 10:27
 */
public class ThreadException {

    private static int a = 10;
    private static int b = 0;


    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            try {
                Thread.sleep(5_000L);
                int result = a / b;
                System.out.println(result);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        // 捕捉没有Caught的异常
        t.setUncaughtExceptionHandler((thread, throwable) -> {
            System.out.println(throwable);
            System.out.println(thread);
        });

        t.start();
    }
}
